load('application');

before(loadIFollowed, {only: ['show', 'edit', 'update', 'destroy']});

action('new', function () {
    this.title = 'New ifollowed';
    this.ifollowed = new IFollowed;
    render();
});

action(function create() {
    IFollowed.create(req.body.IFollowed, function (err, ifollowed) {
        if (err) {
            flash('error', 'IFollowed can not be created');
            render('new', {
                ifollowed: ifollowed,
                title: 'New ifollowed'
            });
        } else {
            flash('info', 'IFollowed created');
            redirect(path_to.ifolloweds());
        }
    });
});

action(function index() {
    this.title = 'IFolloweds index';
    IFollowed.all(function (err, ifolloweds) {
        render({
            ifolloweds: ifolloweds
        });
    });
});

action(function show() {
    this.title = 'IFollowed show';
    render();
});

action(function edit() {
    this.title = 'IFollowed edit';
    render();
});

action(function update() {
    this.ifollowed.updateAttributes(body.IFollowed, function (err) {
        if (!err) {
            flash('info', 'IFollowed updated');
            redirect(path_to.IFollowed(this.IFollowed));
        } else {
            flash('error', 'IFollowed can not be updated');
            this.title = 'Edit ifollowed details';
            render('edit');
        }
    }.bind(this));
});

action(function destroy() {
    this.ifollowed.destroy(function (error) {
        if (error) {
            flash('error', 'Can not destroy ifollowed');
        } else {
            flash('info', 'IFollowed successfully removed');
        }
        send("'" + path_to.ifolloweds() + "'");
    });
});

function loadIFollowed() {
    IFollowed.find(params.id, function (err, ifollowed) {
        if (err || !ifollowed) {
            redirect(path_to.ifolloweds());
        } else {
            this.ifollowed = ifollowed;
            next();
        }
    }.bind(this));
}
